package backend.service.other;

import backend.model.other.LegalHoliday;
import backend.service.base.DBModelServiceImpl;
import org.apache.commons.lang.time.DateUtils;
import org.springframework.stereotype.Service;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

@Service
public class LegalHolidayServiceImpl extends DBModelServiceImpl<LegalHoliday> implements LegalHolidayService {
    @Override
    public List<LegalHoliday> getAllLegalHolidays() {
        return dbModelDao.findByNamedQuery("findAllLegalHolidays");
    }

    @Override
    public LegalHoliday getLegalHolidayByDate(Date date) {
        List<LegalHoliday> results = dbModelDao.findByNamedQueryAndParams(
                "findLegalHolidayByDate", new String[]{"date"}, new Object[]{DateUtils.truncate(date, Calendar.DATE)});
        if (results.size() > 0) {
            return results.get(0);
        }
        return null;
    }

    @Override
    public Class<LegalHoliday> getEntityClass() {
        return LegalHoliday.class;
    }
}
